import Vue from 'vue'
import Router from 'vue-router'

// in development-env not use lazy-loading, because lazy-loading too many pages will cause webpack hot update too slow. so only in production use lazy-loading;
// detail: https://panjiachen.github.io/vue-element-admin-site/#/lazy-loading

Vue.use(Router)

/* Layout */
import Layout from '@/views/layout/Layout'

const home = r => require.ensure([], () => r(require('@/views/home/index')), 'home');
const historyHomeChartDataList = r => require.ensure([], () => r(require('@/views/historyDataList/historyHomeChartDataList/index')), 'historyHomeChartDataList');
const historyOvuolaDataList = r => require.ensure([], () => r(require('@/views/historyDataList/historyOvuolaDataList/index')), 'historyOvuolaDataList');
const login = r => require.ensure([], () => r(require('@/views/login/index')), 'login');
const userManage = r => require.ensure([], () => r(require('@/views/userManage/index')), 'userManage');
const userList = r => require.ensure([], () => r(require('@/views/userManage/userList/index')), 'userList');
const userMemo = r => require.ensure([], () => r(require('@/views/userManage/userList/userMemo/index')), 'userMemo');
const userAllMemo = r => require.ensure([], () => r(require('@/views/userManage/userAllMemo/index')), 'userAllMemo');
const userDetail = r => require.ensure([], () => r(require('@/views/userManage/userList/userDetail/index')), 'userDetail');
const ultrasonic = r => require.ensure([], () => r(require('@/views/userManage/ultrasonic/index')), 'ultrasonic');
const allLabel = r => require.ensure([], () => r(require('@/views/userManage/userLabel/allLabel/index')), 'allLabel');
const userLabelSearch = r => require.ensure([], () => r(require('@/views/userManage/userLabelSearch/index')), 'userLabelSearch');
const serviceList = r => require.ensure([], () => r(require('@/views/customerManage/serviceList/index')), 'serviceList');
const customerManage = r => require.ensure([], () => r(require('@/views/customerManage/index')), 'customerManage');
const pregnancyEcharts = r => require.ensure([], () => r(require('@/views/pregnancyEcharts/index')), 'pregnancyEcharts');
const changePassword = r => require.ensure([], () => r(require('@/views/changePassword/index')), 'changePassword');
const feedback = r => require.ensure([], () => r(require('@/views/customerManage/feedback/index')), 'feedback');
const noDetection = r => require.ensure([], () => r(require('@/views/customerManage/noDetection/index')), 'noDetection');
const newEquipment = r => require.ensure([], () => r(require('@/views/customerManage/newEquipment/index')), 'newEquipment');
const thousandPlanStatus = r => require.ensure([], () => r(require('@/views/customerManage/thousandPlanStatus/index')), 'thousandPlanStatus');
const feedbackHistory = r => require.ensure([], () => r(require('@/views/customerManage/feedback/feedbackHistory/index')), 'feedbackHistory');
// const serviceMessageTemplate = r => require.ensure([], () => r(require('@/views/serviceMessageTemplate/index')), 'serviceMessageTemplate');
const messageManage = r => require.ensure([], () => r(require('@/views/messageManage/index')), 'messageManage');
const sendMessage = r => require.ensure([], () => r(require('@/views/messageManage/sendMessage/index')), 'sendMessage');
const sendNewMessage = r => require.ensure([], () => r(require('@/views/messageManage/sendNewMessage/index')), 'sendNewMessage');
const messageView = r => require.ensure([], () => r(require('@/views/messageManage/messageView/index')), 'messageView');
const onSitePush = r => require.ensure([], () => r(require('@/views/messageManage/onSitePush/index')), 'onSitePush');
const outSitePush = r => require.ensure([], () => r(require('@/views/messageManage/outSitePush/index')), 'outSitePush');
const messageTemplateManage = r => require.ensure([], () => r(require('@/views/messageTemplateManage/index')), 'messageTemplateManage');
const messageTemplate = r => require.ensure([], () => r(require('@/views/messageTemplateManage/messageTemplate/index')), 'messageTemplate');
const youMengPushTemplate = r => require.ensure([], () => r(require('@/views/messageTemplateManage/youMengPushTemplate/index')), 'youMengPushTemplate');
const equipmentList = r => require.ensure([], () => r(require('@/views/equipmentManage/equipmentList/index')), 'equipmentList');
const equipmentHistorybind = r => require.ensure([], () => r(require('@/views/equipmentManage/equipmentHistorybind/index')), 'equipmentHistorybind');
const uploadImg = r => require.ensure([], () => r(require('@/views/uploadImg/index')), 'uploadImg');
const equipmentManage = r => require.ensure([], () => r(require('@/views/equipmentManage/index')), 'equipmentManage');
const accessManage = r => require.ensure([], () => r(require('@/views/teamManage/accessManage/index')), 'accessManage');
const editorAccessManage = r => require.ensure([], () => r(require('@/views/teamManage/accessManage/editorAccessManage/index')), 'editorAccessManage');
const membersManage = r => require.ensure([], () => r(require('@/views/teamManage/membersManage/index')), 'membersManage');
const teamManage = r => require.ensure([], () => r(require('@/views/teamManage/index')), 'teamManage');
const activityManage = r => require.ensure([], () => r(require('@/views/activityManage/index')), 'activityManage');
const taskManage = r => require.ensure([], () => r(require('@/views/activityManage/taskManage/index')), 'taskManage');
const taskList = r => require.ensure([], () => r(require('@/views/activityManage/taskList/index')), 'taskList');
const taskAllStatus = r => require.ensure([], () => r(require('@/views/activityManage/taskAllStatus/index')), 'taskAllStatus');
const voucherList = r => require.ensure([], () => r(require('@/views/activityManage/voucherList/index')), 'voucherList');
const updateExcel = r => require.ensure([], () => r(require('@/views/activityManage/updateExcel/index')), 'updateExcel');
const auditList = r => require.ensure([], () => r(require('@/views/activityManage/auditList/index')), 'auditList');
const pregnancyList = r => require.ensure([], () => r(require('@/views/activityManage/pregnancyList/index')), 'pregnancyList');
const analyzeManage = r => require.ensure([], () => r(require('@/views/analyzeManage/index')), 'analyzeManage');
const userBehaviorLog = r => require.ensure([], () => r(require('@/views/analyzeManage/userBehaviorLog/index')), 'userBehaviorLog');
const userBehaviorData = r => require.ensure([], () => r(require('@/views/analyzeManage/userBehaviorData/index')), 'userBehaviorData');
const qinqinManage = r => require.ensure([], () => r(require('@/views/qinqinManage/index')), 'qinqinManage');
const roleMaking = r => require.ensure([], () => r(require('@/views/qinqinManage/roleMaking/index')), 'roleMaking');
const qinqinFeedBack = r => require.ensure([], () => r(require('@/views/qinqinManage/qinqinFeedBack/index')), 'qinqinFeedBack');
const ovuolaCommunity = r => require.ensure([], () => r(require('@/views/ovuolaCommunity/index')), 'ovuolaCommunity');
const look = r => require.ensure([], () => r(require('@/views/ovuolaCommunity/look/index')), 'look');
const guess = r => require.ensure([], () => r(require('@/views/ovuolaCommunity/guess/index')), 'guess');



/**
* hidden: true                   if `hidden:true` will not show in the sidebar(default is false)
* alwaysShow: true               if set true, will always show the root menu, whatever its child routes length
*                                if not set alwaysShow, only more than one route under the children
*                                it will becomes nested mode, otherwise not show the root menu
* redirect: noredirect           if `redirect:noredirect` will no redirect in the breadcrumb
* name:'router-name'             the name is used by <keep-alive> (must set!!!)
* meta : {
    title: 'title'               the name show in submenu and breadcrumb (recommend set)
    icon: 'svg-name'             the icon show in the sidebar
    breadcrumb: false            if false, the item will hidden in breadcrumb(default is true)
  }
**/
export const constantRouterMap = [{
    path: '/login',
    component: login,
    hidden: true
  },
  {
    path: '/other',
    component: Layout,
    redirect: '/other/changePassword',
    hidden: true,
    meta: {
      title: '其他',
      icon: 'setting'
    },
    children: [{
        path: 'changePassword',
        component: changePassword,
        meta: {
          title: '忘记密码',
        }
      },
      {
        path: 'uploadImg',
        component: uploadImg,
        meta: {
          title: '上传图片',
        }
      }
    ]
  },
  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  }, {
    path: '/',
    component: Layout,
    redirect: '/dashboard',
    children: [{
      path: 'dashboard',
      component: home,
      name: 'dashboard',
      meta: {
        title: '首页',
        icon: 'home',
        noCache: true //如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
      }
    }]
  }
]

/* 初始路由 */
export default new Router({
  // mode: 'history', //后端支持可开
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRouterMap
})



export const asyncRouterMap = [{
  path: '/',
  component: Layout,
  redirect: '/dashboard',
  children: [{
    path: 'dashboard',
    component: home,
    name: 'dashboard2',
    meta: {
      title: '首页',
      icon: 'dashboard',
      noCache: true //如果设置为true，则不会被 <keep-alive> 缓存(默认 false)
    }
  }]
}]


/* 需要权限判断的路由 */
export const allRoutes = [{
    path: '/userManage',
    component: Layout,
    redirect: '/userManage/userList',
    name: 'userManage',
    meta: {
      title: '用户管理',
      icon: 'users',
    },
    children: [{
      path: 'userList',
      component: userManage,
      redirect: '/userManage/userList/userlist',
      name: 'userList',
      meta: {
        title: '用户列表',
      },
      children: [{
        path: 'userlist',
        component: userList,
        meta: {
          title: '用户列表',
          keepAlive: true
        }
      }, {
        path: 'userChart',
        component: pregnancyEcharts,
        name: 'userChart',
        hidden: true,
        meta: {
          title: '用户图表',
        }
      }, {
        path: 'userMemo',
        component: userMemo,
        name: 'userMemo',
        hidden: true,
        meta: {
          title: '用户备注'
        }
      }, {
        path: 'userDetail',
        component: userDetail,
        name: 'userDetail',
        hidden: true,
        meta: {
          title: '用户详情'
        }
      }]
    }, {
      path: 'thousandPlanStatus',
      component: thousandPlanStatus,
      name: 'thousandPlanStatus',
      meta: {
        title: '千人计划',
      }
    }, {
      path: 'ultrasonic',
      component: ultrasonic,
      name: 'ultrasonic',
      meta: {
        title: 'B超计划',
      }
    }, {
      path: 'allLabel',
      component: allLabel,
      name: 'allLabel',
      meta: {
        title: '标签管理',
      }
    }]
  }, {
    path: '/customerManage',
    component: Layout,
    redirect: '/customerManage/serviceList',
    name: 'customerManage',
    meta: {
      title: '客服管理',
      icon: 'customer',
    },
    children: [{
      path: 'serviceList',
      component: customerManage,
      redirect: '/customerManage/serviceList/servicelist',
      name: 'serviceList',
      meta: {
        title: '异常数据'
      },
      children: [{
        path: 'servicelist',
        component: serviceList,
        meta: {
          title: '异常数据',
          keepAlive: true
        }
      }, {
        path: 'serviceChart',
        component: pregnancyEcharts,
        name: 'serviceChart',
        hidden: true,
        meta: {
          title: '异常图表',
        }
      }]
    }, {
      path: 'userAllMemo',
      component: userAllMemo,
      name: 'userAllMemo',
      meta: {
        title: '每日跟进'
      }
    }, {
      path: 'feedback',
      component: customerManage,
      redirect: '/customerManage/feedback/feedbackList',
      name: 'feedback',
      meta: {
        title: '问题反馈',
      },
      children: [{
        path: 'feedbackList',
        component: feedback,
        meta: {
          title: '问题反馈',
          keepAlive: true
        }
      }, {
        path: 'feedbackHistory',
        component: feedbackHistory,
        name: 'feedbackHistory',
        hidden: true,
        meta: {
          title: '异常图表',
        }
      }]
    }, {
      path: 'noDetection',
      component: customerManage,
      redirect: '/customerManage/noDetection/nodetection',
      name: 'noDetection',
      meta: {
        title: '近日未检测'
      },
      children: [{
        path: 'nodetection',
        component: noDetection,
        meta: {
          title: '近日未检测',
        }
      }]
    }, {
      path: 'newEquipment',
      component: newEquipment,
      name: 'newEquipment',
      meta: {
        title: '新增设备',
        keepAlive: true
      }
    }]
  }, {
    path: '/activityManage',
    component: Layout,
    redirect: '/activityManage/taskList',
    name: 'activityManage',
    meta: {
      title: '活动管理',
      icon: 'activity'
    },
    children: [{
        path: 'taskAllStatus',
        component: activityManage,
        redirect: '/activityManage/taskAllStatus/taskallstatus',
        name: 'taskAllStatus',
        meta: {
          title: '任务统计'
        },
        children: [{
          path: 'taskallstatus',
          component: taskAllStatus,
          meta: {
            title: '任务统计'
          }
        }]
      },
      {
        path: 'taskList',
        component: activityManage,
        redirect: '/activityManage/taskList/tasklist',
        name: 'taskList',
        meta: {
          title: '任务列表'
        },
        children: [{
          path: 'tasklist',
          component: taskList,
          meta: {
            title: '任务列表'
          }
        }]
      }, {
        path: 'taskManage',
        component: activityManage,
        redirect: '/activityManage/taskManage/taskmanage',
        name: 'taskManage',
        meta: {
          title: '任务管理'
        },
        children: [{
          path: 'taskmanage',
          component: taskManage,
          meta: {
            title: '任务管理'
          }
        }]
      }, {
        path: 'auditList',
        component: activityManage,
        redirect: '/activityManage/auditList/auditlist',
        name: 'auditList',
        meta: {
          title: '审核记录'
        },
        children: [{
          path: 'auditlist',
          component: auditList,
          meta: {
            title: '审核记录'
          }
        }]
      }, {
        path: 'voucherList',
        component: activityManage,
        redirect: '/activityManage/voucherList/voucherlist',
        name: 'voucherList',
        meta: {
          title: '兑换券列表'
        },
        children: [{
          path: 'voucherlist',
          component: voucherList,
          meta: {
            title: '兑换券列表'
          }
        }]
      }, {
        path: 'updateExcel',
        component: activityManage,
        redirect: '/activityManage/updateExcel/updateexcel',
        name: 'updateExcel',
        meta: {
          title: '更新兑换券'
        },
        children: [{
          path: 'updateexcel',
          component: updateExcel,
          meta: {
            title: '更新兑换券'
          }
        }]
      },
      {
        path: 'pregnancyList',
        component: pregnancyList,
        name: 'pregnancyList',
        meta: {
          title: '好孕接力'
        }
      }
    ]
  }, {
    path: '/messageManage',
    component: Layout,
    redirect: '/messageManage/sendMessageList',
    name: 'messageManage',
    meta: {
      title: '消息管理',
      icon: 'message'
    },
    children: [{
      path: 'sendMessageList',
      component: messageManage,
      redirect: '/messageManage/sendMessageList/sendMessagelist',
      name: 'sendMessageList',
      meta: {
        title: '短信推送',
      },
      children: [{
        path: 'sendMessagelist',
        component: sendMessage,
        meta: {
          title: '短信推送',
        }
      }, {
        path: 'sendNewMessage',
        component: sendNewMessage,
        name: 'sendNewMessage',
        hidden: true,
        meta: {
          title: '新建短信推送',
        }
      }, {
        path: 'messageView',
        component: messageView,
        name: 'messageView',
        hidden: true,
        meta: {
          title: '推送详情',
        }
      }]
    }, {
      path: 'outSitePush',
      component: messageManage,
      redirect: '/messageManage/outSitePush/outSitepush',
      name: 'outSitePush',
      meta: {
        title: '友盟+App推送',
      },
      children: [{
        path: 'outSitepush',
        component: outSitePush,
        meta: {
          title: '友盟+App推送',
        }
      }, {
        path: 'newOutSite',
        component: sendNewMessage,
        name: 'newOutSite',
        hidden: true,
        meta: {
          title: '新建推送',
        }
      }, {
        path: 'messageView',
        component: messageView,
        name: 'messageView1',
        hidden: true,
        meta: {
          title: '推送详情',
        }
      }]
    }, {
      path: 'onSitePush',
      component: messageManage,
      redirect: '/messageManage/onSitePush/onSitepush',
      name: 'onSitepush',
      meta: {
        title: '仅App推送',
      },
      children: [{
        path: 'onSitepush',
        component: onSitePush,
        meta: {
          title: '仅App推送',
        }
      }, {
        path: 'newOnSite',
        component: sendNewMessage,
        name: 'newOnSite',
        hidden: true,
        meta: {
          title: '新建推送',
        }
      }, {
        path: 'messageView',
        component: messageView,
        name: 'messageView2',
        hidden: true,
        meta: {
          title: '推送详情',
        }
      }]
    }]
  }, {
    path: '/messageTemplateManage',
    component: Layout,
    name: 'messageTemplateManage',
    redirect: '/messageTemplateManage/messageTemplate',
    meta: {
      title: '模板管理',
      icon: 'template',
    },
    children: [{
      path: 'messageTemplate',
      component: messageTemplateManage,
      name: 'messageTemplate',
      redirect: '/messageTemplateManage/messageTemplate/messagetemplate',
      meta: {
        title: '短信模板',
      },
      children: [{
        path: 'messagetemplate',
        component: messageTemplate,
        meta: {
          title: '短信模板',
        }
      }]
    }, {
      path: 'youMengPushTemplate',
      component: youMengPushTemplate,
      name: 'youMengPushTemplate',
      redirect: '/messageTemplateManage/youMengPushTemplate/youMengPushtemplate',
      meta: {
        title: '友盟+App模板',
      },
      children: [{
        path: 'youMengPushtemplate',
        component: youMengPushTemplate,
        meta: {
          title: '友盟+App模板',
        }
      }]
    }]
  }, {
    path: '/equipmentManage',
    component: Layout,
    redirect: '/equipmentManage/equipmentList',
    name: 'equipmentManage',
    alwaysShow: false,
    meta: {
      title: '设备管理',
      icon: 'equipment'
    },
    children: [{
      path: 'equipmentList',
      component: equipmentManage,
      name: 'equipmentList',
      redirect: '/equipmentManage/equipmentList/equipmentlist',
      meta: {
        title: '设备列表',
      },
      children: [{
        path: 'equipmentlist',
        component: equipmentList,
        meta: {
          title: '设备列表',
        }
      }, {
        path: 'equipmentHistorybind',
        component: equipmentHistorybind,
        name: 'equipmentHistorybind',
        hidden: true,
        meta: {
          title: '绑定历史',
        }
      }]
    }]
  }, {
    path: '/dataManage',
    component: Layout,
    name: 'dataManage',
    redirect: '/dataManage/historyHomeChartDataList',
    meta: {
      title: '数据管理',
      icon: 'data'
    },
    children: [{
      path: 'historyHomeChartDataList',
      component: historyHomeChartDataList,
      name: 'historyHomeChartDataList',
      meta: {
        title: '历史数据',
      }
    }, {
      path: 'historyOvuolaDataList',
      component: historyOvuolaDataList,
      name: 'historyOvuolaDataList',
      hidden: true,
      meta: {
        title: '历史数据',
      }
    }]
  }, {
    path: '/teamManage',
    component: Layout,
    name: 'teamManage',
    redirect: '/teamManage/membersManage',
    meta: {
      title: '团队管理',
      icon: 'setting'
    },
    children: [{
        path: 'membersManage',
        component: teamManage,
        name: 'membersManage',
        redirect: '/teamManage/membersManage/membersmanage',
        meta: {
          title: '成员管理',
        },
        children: [{
          path: 'membersmanage',
          component: membersManage,
          meta: {
            title: '成员管理',
          }
        }]
      },
      {
        path: 'accessManage',
        component: teamManage,
        name: 'accessManage',
        redirect: '/teamManage/accessManage/accessmanage',
        meta: {
          title: '权限管理',
        },
        children: [{
          path: 'accessmanage',
          component: accessManage,
          meta: {
            title: '权限管理',
          }
        }, {
          path: 'editorAccessManage',
          component: editorAccessManage,
          name: 'editorAccessManage',
          hidden: true,
          meta: {
            title: '编辑权限',
          }
        }]
      }
    ]
  }, {
    path: '/analyzeManage',
    component: Layout,
    name: 'analyzeManage',
    redirect: '/analyzeManage/userBehaviorLog',
    meta: {
      title: '数据分析',
      icon: 'analyze'
    },
    children: [{
        path: 'userBehaviorLog',
        component: analyzeManage,
        name: 'userBehaviorLog',
        redirect: '/analyzeManage/userBehaviorLog/userbehaviorlog',
        meta: {
          title: 'APP行为日志'
        },
        children: [{
          path: 'userbehaviorlog',
          component: userBehaviorLog,
          meta: {
            title: 'APP行为日志',
          }
        }]
      },
      {
        path: 'userBehaviorData',
        component: analyzeManage,
        name: 'userBehaviorData',
        redirect: '/analyzeManage/userBehaviorData/userbehaviordata',
        meta: {
          title: 'APP行为数据'
        },
        children: [{
          path: 'userbehaviordata',
          component: userBehaviorData,
          meta: {
            title: 'APP行为数据',
          }
        }]
      }

    ]
  }, {
    path: '/qinqinManage',
    component: Layout,
    name: 'qinqinManage',
    redirect: '/qinqinManage/roleMaking',
    meta: {
      title: '亲亲',
      icon: 'analyze'
    },
    children: [{
      path: 'roleMaking',
      component: qinqinManage,
      name: 'roleMaking',
      redirect: '/analyzeManage/roleMaking/rolemaking',
      meta: {
        title: '角色塑造'
      },
      children: [{
        path: 'rolemaking',
        component: roleMaking,
        meta: {
          title: '角色塑造',
        }
      }]
    }, {
      path: 'feedBackList',
      component: qinqinFeedBack,
      name: 'feedBackList',
      meta: {
        title: '亲亲用户反馈'
      },
    }]
  }, {
    path: '/ovuolaCommunity',
    component: Layout,
    name: 'ovuolaCommunity',
    redirect: '/ovuolaCommunity/ovuolacommunity',
    meta: {
      title: '佑蜜社区',
      icon: 'analyze'
    },
    children: [{
      path: 'ovuolacommunity',
      component: ovuolaCommunity,
      redirect: '/ovuolaCommunity/ovuolacommunity/guess',
      name: 'ovuolacommunity',
      meta: {
        title: '猜一猜'
      },
      children: [{
        path: 'guess',
        component: guess,
        meta: {
          title: '猜一猜',
        }
      }]
    }, {
      path: 'look',
      component: look,
      name: 'look',
      meta: {
        title: '看一看'
      }
    }]
  },

  //必须放最后
  {
    path: '*',
    redirect: '/404',
    hidden: true,
    meta: {
      title: '404',
    }
  }
]
